package com.yidu.ruifeng_logistics.service.impl;

import com.yidu.ruifeng_logistics.dao.LogisticsCarDao;
import com.yidu.ruifeng_logistics.dao.LogisticsStaffDao;
import com.yidu.ruifeng_logistics.entity.LogisticsDriver;
import com.yidu.ruifeng_logistics.dao.LogisticsDriverDao;
import com.yidu.ruifeng_logistics.service.LogisticsDriverService;
import com.yidu.ruifeng_logistics.vo.DriverVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 司机表(LogisticsDriver)表服务实现类
 *
 * @author makejava
 * @since 2021-03-18 10:19:03
 */
@Service("logisticsDriverService")
public class LogisticsDriverServiceImpl implements LogisticsDriverService {
    @Resource
    private LogisticsDriverDao logisticsDriverDao;
    @Resource
    private LogisticsCarDao logisticsCarDao;

    /**
     * 通过ID查询单条数据
     *
     * @param driverId 主键
     * @return 实例对象
     */
    @Override
    public LogisticsDriver queryById(Integer driverId) {
        return this.logisticsDriverDao.queryById(driverId);
    }

    @Override
    public LogisticsDriver queryByStaffId(Integer staffId) {
        return logisticsDriverDao.queryByStaffId(staffId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<LogisticsDriver> queryAllByLimit(int offset, int limit) {
        return this.logisticsDriverDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param logisticsDriver 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsDriver insert(LogisticsDriver logisticsDriver) {
        this.logisticsDriverDao.insert(logisticsDriver);
        return logisticsDriver;
    }

    /**
     * 修改数据
     *
     * @param logisticsDriver 实例对象
     * @return 实例对象
     */
    @Override
    public LogisticsDriver update(LogisticsDriver logisticsDriver) {
        this.logisticsDriverDao.update(logisticsDriver);
        return this.queryById(logisticsDriver.getDriverId());
    }

    /**
     * 通过主键删除数据
     *
     * @param driverId 主键
     * @return 是否成功
     */
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteById(Integer driverId) {
        String[] s = {String.valueOf(driverId)};
        logisticsCarDao.deleteDriverId(s);
        return this.logisticsDriverDao.deleteById(driverId) > 0;
    }

    @Override
    public List<DriverVo> queryAll(DriverVo driverVo) {
        return this.logisticsDriverDao.queryAll(driverVo);
    }

    @Transactional(rollbackFor=Exception.class)
    @Override
    public int deleteAll(String ids) {
        String[] s = ids.split(",");
        logisticsCarDao.deleteDriverId(s);
        return logisticsDriverDao.deleteAll(s);
    }

}
